package web.controller.employer;

import common.consts.ContentType;
import common.validation.ValidationResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import service.RatingService;
import service.ServiceResponse;
import web.Routes;
import web.controller.Base;
import web.req.RatingRequest;
import web.security.Protection;

/**
 * Created by Administrator on 2015/7/3.
 */

@RestController("employerRating")
@RequestMapping(Routes.Employer.RATING)
public class Rating extends Base {
    @Autowired
    private RatingService ratingService;

    @Protection
    @RequestMapping(method = RequestMethod.POST, produces = ContentType.JSON)
    public ServiceResponse rate(@RequestBody RatingRequest request) {

        ValidationResult result = request.validate();
        if (result.isFailed()) {
            return fail(result.getMessage());
        }

        long employer = getUserIdFromAuthHeader();

        long user = request.getRatee();
        long recruitment = request.getRecruitment();
        String rate = request.getRate();
        String comment = request.getComment();

        return ratingService.rate2User(employer, user, recruitment, rate, comment);
    }
}
